<?php
namespace Tbf\Component\Image;
/**
 * rectangle
 */
class Rectangle {
    /**
     * min value of x (include)
     * @var float
     */
    protected $x;
    /**
     * min value of y (include)
     * @var float
     */
    protected $y;
    /**
     * @var float
     */
    protected $width;
    /**
     * @var float
     */
    protected $height;

    /**
     * @param mixed $height
     */
    public function setHeight($height)
    {
        $this->height = $height;
        return $this;
    }

    /**
     * @return mixed
     */
    public function getHeight()
    {
        return $this->height;
    }

    /**
     * @param mixed $width
     */
    public function setWidth($width)
    {
        $this->width = $width;
        return $this;
    }

    /**
     * @return mixed
     */
    public function getWidth()
    {
        return $this->width;
    }

    /**
     * @param mixed $x
     */
    public function setX($x)
    {
        $this->x = $x;
        return $this;
    }

    /**
     * @return mixed
     */
    public function getX()
    {
        return $this->x;
    }

    /**
     * @param mixed $y
     */
    public function setY($y)
    {
        $this->y = $y;
        return $this;
    }

    /**
     * @return mixed
     */
    public function getY()
    {
        return $this->y;
    }

    /**
     * max value of x (the pixel is not include)
     * @return float
     */
    public function getMaxX(){
        return $this->x + $this->width;
    }

    /**
     * @return Rectangle
     */
    public function copy(){
        return clone $this;
    }
    public function getMinX(){
        return $this->x;
    }
    public function getMaxY(){
        return $this->y + $this->height;
    }
    public function getMinY(){
        return $this->y;
    }
    public function isInRectangle(Rectangle $rect){
        if ($this->getMaxX()>$rect->getMaxX()){
            return false;
        }
        if ($this->getMinX()<$rect->getMinX()){
            return false;
        }
        if ($this->getMaxY()>$rect->getMaxY()){
            return false;
        }
        if ($this->getMinY()<$rect->getMinY()){
            return false;
        }
        return true;
    }
    public function offset($x,$y){
        $obj = $this->copy();
        $obj->x += $x;
        $obj->y += $y;
        return $obj;
    }
}